//
//  SAOpinionFeedbackViewController.m
//  SunOn
//
//  Created by RazeenCheng on 2017/5/4.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//

#import "SAOpinionFeedbackViewController.h"

@interface SAOpinionFeedbackViewController ()<UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UIView *backView;
@property (weak, nonatomic) IBOutlet UITextView *textView;


@end

@implementation SAOpinionFeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.backView.layer.borderColor = [[UIColor colorWithHexString:@"EEEEEE"] CGColor];
    self.backView.layer.borderWidth = 1;
    
    [self prepareForNavigation];
    
    self.textView.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - Navigation
- (void)prepareForNavigation
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 40, 20);
    [button setTitle:@"提交" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithHexString:@"000000"] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:16];
    [button addTarget:self action:@selector(rightButtonAction) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
}

- (void)rightButtonAction
{
    [self performSelector:@selector(backAction) withObject:nil afterDelay:1];
}

- (void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if ([self.textView isFirstResponder]) {
        [self.textView resignFirstResponder];
    }
}



#pragma mark - UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if ([textView.text isEqualToString:@"请输入您的意见或建议，我们将努力做的更好"]) {
        textView.text = @"";
        textView.textColor = [UIColor blackColor];
    }
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if ([textView.text isEqualToString:@""]) {
        textView.text = @"请输入您的意见或建议，我们将努力做的更好";
        textView.textColor = [UIColor colorWithHexString:@"CCCCCC"];
    }
}

@end
